<template>
    <div class="goods-brand">
        <div class="goods-brand-card">
            <div class="goods-brand-head">
                <Row :gutter="5">
                    <Col span="4">
                        <DatePicker  clearable v-model="searchData.timeStartEnd" style="width: 100%" type="daterange" placeholder="时间筛选"></DatePicker>
                    </Col>
                    <Col span="4">
                        <Input clearable v-model="searchData.brandName" placeholder="品牌名称" type="text"></Input>
                    </Col>
                    <Col span="4">
                        <Select clearable v-model="searchData.isShow" placeholder="选择隐藏显示">
                            <Option :value="-1">隐藏</Option>
                            <Option :value="1">显示</Option>
                        </Select>
                    </Col>
                    <Col span="4">
                        <Select clearable v-model="searchData.isTimeUp" placeholder="创建时间排序">
                            <Option :value="1">升序</Option>
                            <Option :value="2">降序</Option>
                        </Select>
                    </Col>
                    <Col span="4">
                        <Select clearable v-model="searchData.type" placeholder="按品牌分类">
                            <Option v-for="(key,value) in type" :value="key.catid">{{key.catname}}</Option>
                        </Select>
                    </Col>
                    <Col span="4">
                        <router-link :to="{name:'goods-brand-edit-nocache'}">
                            <Button class="subSearch" type="primary"><Icon type="plus-round"></Icon> 新增品牌</Button>
                        </router-link>
                        <Button :loading="search_loading" @click="searchGetList" class="subSearch" type="primary"><Icon type="ios-pulse-strong"></Icon> 筛 选</Button>
                    </Col>
                </Row>
            </div>
            <i-table height="680" stripe :columns="columns" :data="data"></i-table>
            <div style="padding: 15px;">
                <Page @on-page-size-change="changeTiao" @on-change="changePage" :current="index" :total="total" show-elevator show-sizer :placement="'top'" :page-size="page_con" :page-size-opts="[10, 15, 20, 30, 40, 50]"></Page>
            </div>
        </div>
        <Modal v-model="modal2" width="360">
            <p slot="header" style="color:#f60;text-align:center">
                <Icon type="information-circled"></Icon>
                <span>删除确认</span>
            </p>
            <div style="text-align:center">
                <p>是否继续删除？</p>
            </div>
            <div slot="footer">
                <Button type="error" size="large" long :loading="modal_loading" @click="del">删除</Button>
            </div>
        </Modal>
    </div>
</template>
<script>
    export default {
        name:"goods-brand",
        data(){
            return{
                columns:[
                    {
                        title: '序号',
                        type: 'index',
                        width: 60,
                        align:"center",
                    },
                    {
                        title: '品牌名称',
                        key: 'brandname',
                        align:"center",
                    },
                    {
                        title: '品牌介绍',
                        key: 'branddesc',
                        align:"center",
                        render:(h,params)=>{
                            return h("div",{
                                domProps: {
                                    innerHTML: params.row.branddesc
                                },
                            })
                        }
                    },
                    {
                        title: '图标',
                        key: 'brandico',
                        align:"center",
                        render:(h,params)=>{
                            if(params.row.articleimg==""){
                                return "暂无"
                            }else{
                                return h("div",{
                                    style:{
                                        cursor: "pointer",
                                    },
                                    on:{
                                        mouseover:(e)=>{
                                            this.$store.commit("setImgData",{
                                                src:e.target.src||e.target.getElementsByTagName("img")[0].src||"",
                                                x:e.x+50+"px",
                                                y:e.y-60+"px",
                                            })
                                        },
                                        mousemove:(e)=>{
                                            this.$store.commit("setImgData",{
                                                src:e.target.src||e.target.getElementsByTagName("img")[0].src||"",
                                                x:e.x+50+"px",
                                                y:e.y-60+"px",
                                            })
                                        },
                                        mouseout:(e)=>{
                                            this.$store.commit("setImgData",{
                                                src:"",
                                                x:"0px",
                                                y:"0px",
                                            })
                                        }
                                    }
                                },[
                                    h("img",
                                        {
                                            attrs:{
                                                src:params.row.brandico
                                            },
                                            style:{
                                                width:"42px",
                                                height:"42px",
                                                borderRadius:"4px",
                                                margin:"0px auto",
                                                display:"block",
                                            },
                                        })
                                ])
                            }
                        }
                    },
                    {
                        title: '是否显示',
                        key: 'status',
                        align:"center",
                        render:(h,params)=>{
                            return h("div",
                                [
                                    h("Icon",{
                                        props:{type: params.row.status==1?'eye':'eye-disabled'}
                                    }),
                                    h("span",params.row.status==1?' 显示':' 隐藏')
                                ]
                            )
                        }
                    },
                    {
                        title: '操作',
                        key: 'action',
                        align: 'center',
                        render: (h, params) => {
                            return h('ButtonGroup', [
                                h('Button', {
                                    props: {
                                        type: 'warning',
                                    },
                                    on: {
                                        click: () => {
                                            this.tiao(params.index)
                                        }
                                    }
                                },"修改"),
                                h('Button', {
                                    props: {
                                        type: 'error',
                                    },
                                    on: {
                                        click: () => {
                                            this.remove(params.index)
                                        }
                                    }
                                }, '删除')
                            ]);
                        }
                    },
                ],
                data:[],
                total:0,
                index:1,
                page_con:15,
                modal2:false,
                doIndex:0,//操作的下标
                modal_loading:false,
                searchData:{
                    timeStartEnd:[],//两个时间内的赛选
                    isShow:"",//隐藏和显示的赛选
                    isTimeUp:"",//时间排序
                    type:"",//品牌分类
                    brandName:"",//品牌名称
                },
                search_loading:false,
                type:[],
            }
        },
        activated(){
            this.getGoodsBrand()
            this.getType()
        },
        methods:{
            getType(){
                this.getJsonData("Cat/getOneCat",{})
                    .then((res) => {
                        this.type=res.data
                    })
            },
            getGoodsBrand(){
                this.getJsonData("Pinpai/getAllPinpai",{
                    num:this.page_con,
                    page:this.index,
                    begin:this.searchData.timeStartEnd[0]?this.searchData.timeStartEnd[0]/1000:"",
                    last:this.searchData.timeStartEnd[1]?this.searchData.timeStartEnd[1]/1000:"",
                    brandName:this.searchData.brandName,
                    status:this.searchData.isShow,
                    sort:this.searchData.isTimeUp,
                    cat:this.searchData.type,
                },true)
                    .then((res)=>{
                        this.data=res.data
                        this.total=parseInt(res.count)
                        this.search_loading=false
                    })
                    .catch((res)=>{
                        this.search_loading=false
                    })
            },
            changePage(n){
                this.index=n
                this.getGoodsBrand()
            },
            changeTiao(num){
                this.page_con=num
                this.index=1
                this.getGoodsBrand()
            },
            remove(n){
                this.doIndex=n
                this.modal2=true
            },
            del(){
                this.modal_loading = true;
                this.getJsonData("Pinpai/deletePinpai",{brandId:this.data[this.doIndex].brandid},true)
                    .then((res)=>{
                        this.getGoodsBrand()
                        this.modal_loading = false;
                        this.modal2 = false;
                        this.$Message.success('删除成功');
                    }).catch((res)=>{
                    this.modal_loading = false;
                    this.modal2 = false;
                })
            },
            searchGetList(){
                this.search_loading=true
                this.index=1
                this.getGoodsBrand()
            },
            tiao(n){
                this.$router.push({name:"goods-brand-edit-nocache",query:{isEdit:true,id:this.data[n].brandid}})
            }
        },
    }
</script>
<style lang="less">
    @import "./goods-brand";
</style>